# 第 5 章 if 语句
# 5.1 一个简单示例
cars = ['audi', 'bmw', 'ft', 'dz']
for car in cars:
    if car == 'bmw':
        print(car.upper())
    else:
        print(car.lower())

# 5.2 条件测试
# 5.2.1 检查是否相等
car='bmw'
print(car == 'bmw')
print(car == 'audi')
# 5.2.2 检查是否相等时不考虑大小写
car = 'Bmw'
print(car.lower() == 'bmw')
# 5.2.3 检查是否不相等
car = 'Bmw'
if car != 'zzp':
    print("buy it")
# 5.2.4 比较数字
age=18
print(age == 18)
print(age != 18)
print(age > 19)
print(age < 20)
print(age >= 10)
print(age <= 20)
# 5.2.5 检查多个条件
# 1. 使用and 检查多个条件
age1=29
age2=30
print(age1 >= 21 and age2>=22)
print(age1 >= 21 and age2<=22)
# 5.2.6 检查特定值是否包含在列表中
cars = ['audi', 'bmw', 'ft', 'dz']
print('dz' in cars)
print('dz2' in cars)
# 5.2.7 检查特定值是否不包含在列表中
cars = ['audi', 'bmw', 'ft', 'dz']
car='zz'
if car not in cars:
    print(car.title())
# 5.2.8 布尔表达式
game = True
can = False

# 5.3 if 语句
age = 19
if age >= 18:
    print("你已经长大了")
    print("懂事了")
# 5.3.2 if-else 语句
age = 10
if age >= 18:
    print("你已经长大了")
    print("懂事了")
else:
    print("你还小")
# 5.3.3 if-elif-else 结构
age=12
if age < 10:
    print("免费")
elif age < 18:
    print("优惠")
else:
    print("全价")
# 5.3.4 使用多个elif 代码块
age = 25
if age < 8:
    print("免费")
elif age < 18:
    print("优惠")
elif age < 28:
    print("优惠一点")
else:
    print("全价")
# 5.3.5 省略else 代码块
# 5.3.6 测试多个条件
requested_toppings = ['mushrooms', 'extra cheese']
if 'mushrooms' in requested_toppings:
    print("Adding mushrooms.")
if 'pepperoni' in requested_toppings:
    print("Adding pepperoni.")
if 'extra cheese' in requested_toppings:
    print("Adding extra cheese.")
# 5.4 使用if 语句处理列表
cars = ['audi', 'bmw', 'ft', 'dz']
for car in cars:
    if car == 'dz':
       print(car)
    else:
        print("豪车啊")
# 5.4.2 确定列表不是空的
requested_toppings = []
if requested_toppings:
    for requested_topping in requested_toppings:
        print("hahaha"+requested_topping)
else:
    print("没有任何数据")
# 5.4.3 使用多个列表
cars = ['audi', 'bmw', 'ft', 'dz']
number = ['1', 'bmw', '3', '4', '5']
for car in cars:
    if car in number:
        print("找到了"+car)
    else:
        print("没找到")
print("循环结束")
